package com.ming.controller;

import com.ming.controller.utils.R;
import com.ming.pojo.Book;
import com.ming.service.iBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//封装状态与数据
@RestController
@RequestMapping("/Books")
public class BookController2 {
    @Value("${country}")
    private String country;

    //  封装全部Value
    @Autowired
    private Environment environment;

    @Autowired
    private iBookService iBookService;

    @GetMapping()
    public String getById() {
        System.out.println("spring");

        System.out.println(environment.getProperty("${tempDir}"));

        System.out.println();
        return "spring";
    }

    @RequestMapping("/list")
    public List<Book> getAll() {
        return iBookService.list();
    }

    @RequestMapping("/save")
    public R save(@RequestBody Book book) {
        R r = new R(iBookService.save(book));
        return r;
    }

    @RequestMapping("/{id}")
    public R getById(@PathVariable Integer id) {
        R r = new R(true, iBookService.getById(id));
        return r;
    }


}
